#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef int (*function) (char *, char *);

int callback_cpy(char *des, char *src)
{
	strcpy(des, src);

	return 0;
}

int callback_ncpy(char *des, char *src)
{
	strcpy(src, "modified");
	strncpy(des, src, 8);
	des[8] = '\0';

	return 0;
}

void test_other(function fun)
{
	char a[20];
	char b[20] = "xiaozhi";

	if (fun){
		fun(a, b);
	}

	printf("a = %s\n", a);
}

void r_test(function fun)
{
	test_other(fun);
}

void test(char *a, char *b, int (*fun)(char *c, char *d))
{
	strcat(a, b);
	printf("%s\n", a);

	fun(a,b);
	printf("%s\n", a);
}



int main()
{
	char buf[128] = "xiaozhi";
	char *p = NULL;

	test_other(callback_cpy);
	test_other(callback_ncpy);

	test(buf, "wise", callback_cpy);

	r_test(callback_cpy);
		
	free(p);
	p = "xiaozhi";
	printf("p is %s\n", p);	// p is xiaozhi

	return 0;
}



